package com.kyrioscraft.cloud.ribbonrest;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


import java.util.ArrayList;
import java.util.List;

@RestController
@DefaultProperties(defaultFallback = "defaultFallback")
public class TestController {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
            value = "3000")
    })
    @GetMapping("/test")
    public List<String> test(){
        return restTemplate.getForObject("http://REST-API/test",List.class);
    }

    public List<String> defaultFallback(){
        List<String> lst = new ArrayList<>();
        lst.add("拼命加载中...");
        return lst;
    }
}
